'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 14_study_weaviate_filter.py
* @Time: 2025/10/28
* @All Rights Reserve By Brtc
'''
import dotenv
import weaviate
from langchain_openai import  OpenAIEmbeddings
from langchain_weaviate import WeaviateVectorStore
from weaviate.collections.classes.filters import Filter

dotenv.load_dotenv()
embedding = OpenAIEmbeddings(model="text-embedding-3-small")
client = weaviate.connect_to_local("192.168.106.129", 8080)
"""
client = weaviate.connect_to_weaviate_cloud(
    cluster_url="https://g2erxw7ety2jjvovjy2d0g.c0.asia-southeast1.gcp.weaviate.cloud",
    auth_credentials=AuthApiKey("TzRXakNkVEF1RnZJTWMvbl9QcERLY2lUbmRESzhjbjF4U1o4YWVwYnRHUTh2ME5FeUdGOFlhYjUzMUw4PV92MjAw")
)"""
db = WeaviateVectorStore(client=client, index_name="DataTest", text_key="text", embedding=embedding)
texts = [ "笨笨是一只很喜欢睡觉的猫咪",
    "我喜欢在夜晚听音乐，这让我感到放松。",
    "猫咪在窗台上打盹，看起来非常可爱。",
    "学习新技能是每个人都应该追求的目标。",
    "我最喜欢的食物是意大利面，尤其是番茄酱的那种。",
    "昨晚我做了一个奇怪的梦，梦见自己在太空飞行。",
    "我的手机突然关机了，让我有些焦虑。",
    "阅读是我每天都会做的事情，我觉得很充实。",
    "他们一起计划了一次周末的野餐，希望天气能好。",
    "我的狗喜欢追逐球，看起来非常开心。",
]

metadata=[
    {"page":1},
    {"page":2},
    {"page":3},
    {"page":4},
    {"page":5, "account_id":1},
    {"page":6},
    {"page":7},
    {"page":8},
    {"page":9},
    {"page":10},
]
ids = db.add_texts(texts=texts, metadatas=metadata)


filter = Filter.by_property("page").greater_or_equal(5)
search_list = db.similarity_search_with_score("我有一只猫叫做笨笨", filters=filter)
for one in search_list:
    print(one)
client.close()